package com.ejoysoft.wlanyz.business;

import com.ejoysoft.auth.MD5;
import com.ejoysoft.common.*;
import com.ejoysoft.common.exception.UserUnitIdException;
import com.ejoysoft.wlanyz.system.Unit;
import com.ejoysoft.wlanyz.system.User;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import org.jfree.ui.Size2D;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.HashMap;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

public class Acceptance {
	private Globa globa;
    private DbConnect db;

    public Acceptance() {
    }

    public Acceptance(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    public Acceptance(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }
    
  //记录集转化为对象
    public Acceptance load (ResultSet rs,boolean isView){
    	Acceptance smLoad = new Acceptance();
		try {
			smLoad.setStrcity(rs.getString("strcity"));
			smLoad.setStrtown(rs.getString("strtown"));
			smLoad.setStrtaskname(rs.getString("strtaskname"));
			smLoad.setStrapname(rs.getString("device_name"));
			smLoad.setStrhpname(rs.getString("strhotpotname"));
			smLoad.setStrtext(rs.getString("strtext"));
			smLoad.setStrtesttime(rs.getString("dtcreatdate"));
			smLoad.setStrhpaddr(rs.getString("strhotpotaddr"));
			smLoad.setStrid(rs.getString("strid"));
			smLoad.setIntap_relevacy_sucrate(rs.getString("intap_relevacy_sucrate"));
			smLoad.setIntap_relevacy_delay(rs.getString("intap_relevacy_delay"));
			smLoad.setIntweb_auth_sucrate(rs.getString("intweb_auth_sucrate"));
			smLoad.setIntweb_off_sucrate(rs.getString("intweb_off_sucrate"));			
			smLoad.setIntpeap_auth_sucrate(rs.getString("intpeap_auth_sucrate"));
			smLoad.setIntpeap_off_sucrate(rs.getString("intpeap_off_sucrate"));			
			smLoad.setInthttp_req_sucrate(rs.getString("inthttp_req_sucrate"));
			smLoad.setIntping_sucrate(rs.getString("intping_sucrate"));
			smLoad.setIntftp_up_sucrate(rs.getString("intftp_up_sucrate"));
			smLoad.setIntftp_down_sucrate(rs.getString("intftp_down_sucrate"));			
			smLoad.setIntuser_seg_sucrate(rs.getString("intuser_seg_sucrate"));
			smLoad.setIntuser_roam_sucrate(rs.getString("intuser_roam_sucrate"));
			smLoad.setIntweb_up_delay(rs.getString("intweb_up_delay"));
			smLoad.setIntweb_down_delay(rs.getString("intweb_down_delay"));
			
			smLoad.setIntpeap_up_delay(rs.getString("intpeap_up_delay"));
			smLoad.setInthttp_resp_delay(rs.getString("inthttp_resp_delay"));
			smLoad.setIntping_delay(rs.getString("intping_delay"));
			smLoad.setIntftp_up_speed(rs.getString("intftp_up_speed"));
			smLoad.setIntftp_down_speed(rs.getString("intftp_down_speed"));
			smLoad.setStrtaskid(rs.getString("strtaskid"));
			smLoad.setIntrssi(rs.getString("intrssi"));
		} catch (Exception e){
			e.printStackTrace();
		}
		return smLoad;
	}
    
    private String intrssi;
    

	public String getIntrssi() {
		return intrssi;
	}

	public void setIntrssi(String intrssi) {
		this.intrssi = intrssi;
	}

	private String strtaskid;
    
    public String getStrtaskid() {
		return strtaskid;
	}

	public void setStrtaskid(String strtaskid) {
		this.strtaskid = strtaskid;
	}

	private String intpeap_up_delay;
    private String inthttp_resp_delay;
    private String intping_delay;
    private String intftp_up_speed;
    private String intftp_down_speed;
    
    public String getIntpeap_up_delay() {
		return intpeap_up_delay;
	}

	public void setIntpeap_up_delay(String intpeapUpDelay) {
		intpeap_up_delay = intpeapUpDelay;
	}

	public String getInthttp_resp_delay() {
		return inthttp_resp_delay;
	}

	public void setInthttp_resp_delay(String inthttpRespDelay) {
		inthttp_resp_delay = inthttpRespDelay;
	}

	public String getIntping_delay() {
		return intping_delay;
	}

	public void setIntping_delay(String intpingDelay) {
		intping_delay = intpingDelay;
	}

	public String getIntftp_up_speed() {
		return intftp_up_speed;
	}

	public void setIntftp_up_speed(String intftpUpSpeed) {
		intftp_up_speed = intftpUpSpeed;
	}

	public String getIntftp_down_speed() {
		return intftp_down_speed;
	}

	public void setIntftp_down_speed(String intftpDownSpeed) {
		intftp_down_speed = intftpDownSpeed;
	}

	private String intuser_seg_sucrate;
    private String intuser_roam_sucrate;
    private String intweb_up_delay;
    private String intweb_down_delay;
    
    public String getIntuser_seg_sucrate() {
		return intuser_seg_sucrate;
	}

	public void setIntuser_seg_sucrate(String intuserSegSucrate) {
		intuser_seg_sucrate = intuserSegSucrate;
	}

	public String getIntuser_roam_sucrate() {
		return intuser_roam_sucrate;
	}

	public void setIntuser_roam_sucrate(String intuserRoamSucrate) {
		intuser_roam_sucrate = intuserRoamSucrate;
	}

	public String getIntweb_up_delay() {
		return intweb_up_delay;
	}

	public void setIntweb_up_delay(String intwebUpDelay) {
		intweb_up_delay = intwebUpDelay;
	}

	public String getIntweb_down_delay() {
		return intweb_down_delay;
	}

	public void setIntweb_down_delay(String intwebDownDelay) {
		intweb_down_delay = intwebDownDelay;
	}

	private String inthttp_req_sucrate;
    private String intping_sucrate;
    private String intftp_up_sucrate;
    private String intftp_down_sucrate;
    
    public String getInthttp_req_sucrate() {
		return inthttp_req_sucrate;
	}

	public void setInthttp_req_sucrate(String inthttpReqSucrate) {
		inthttp_req_sucrate = inthttpReqSucrate;
	}

	public String getIntping_sucrate() {
		return intping_sucrate;
	}

	public void setIntping_sucrate(String intpingSucrate) {
		intping_sucrate = intpingSucrate;
	}

	public String getIntftp_up_sucrate() {
		return intftp_up_sucrate;
	}

	public void setIntftp_up_sucrate(String intftpUpSucrate) {
		intftp_up_sucrate = intftpUpSucrate;
	}

	public String getIntftp_down_sucrate() {
		return intftp_down_sucrate;
	}

	public void setIntftp_down_sucrate(String intftpDownSucrate) {
		intftp_down_sucrate = intftpDownSucrate;
	}

	private String intpeap_auth_sucrate;
    private String intpeap_off_sucrate;
    
    public String getIntpeap_auth_sucrate() {
		return intpeap_auth_sucrate;
	}

	public void setIntpeap_auth_sucrate(String intpeapAuthSucrate) {
		intpeap_auth_sucrate = intpeapAuthSucrate;
	}

	public String getIntpeap_off_sucrate() {
		return intpeap_off_sucrate;
	}

	public void setIntpeap_off_sucrate(String intpeapOffSucrate) {
		intpeap_off_sucrate = intpeapOffSucrate;
	}

	private String intweb_auth_sucrate;
    private String intweb_off_sucrate;
    
    public String getIntweb_auth_sucrate() {
		return intweb_auth_sucrate;
	}

	public void setIntweb_auth_sucrate(String intwebAuthSucrate) {
		intweb_auth_sucrate = intwebAuthSucrate;
	}

	public String getIntweb_off_sucrate() {
		return intweb_off_sucrate;
	}

	public void setIntweb_off_sucrate(String intwebOffSucrate) {
		intweb_off_sucrate = intwebOffSucrate;
	}

	private String intap_relevacy_sucrate;
    private String intap_relevacy_delay;
    
	public String getIntap_relevacy_sucrate() {
		return intap_relevacy_sucrate;
	}

	public void setIntap_relevacy_sucrate(String intapRelevacySucrate) {
		intap_relevacy_sucrate = intapRelevacySucrate;
	}

	public String getIntap_relevacy_delay() {
		return intap_relevacy_delay;
	}

	public void setIntap_relevacy_delay(String intapRelevacyDelay) {
		intap_relevacy_delay = intapRelevacyDelay;
	}

	//
	public String returnTskId(String where) {
  	  String strtaskid = "";
        try {
            String strSql = "select distinct strtaskid from  wlan_test_result ".concat(where);
            //System.out.println(strSql+"!!!!!!!!!!!!strtaskid");
            ResultSet rs = db.executeQuery(strSql);
            if (rs != null){
          	 while (rs.next()) {
                   strtaskid=rs.getString("STRTASKID");
				}
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        db.closeCon();
        return strtaskid;
    } 
	
	//获取所有已测的验收测试的所有相关信息
    public Vector<Acceptance> list(String where,int startRow, int rowCount) {
        Vector<Acceptance> beans = new Vector<Acceptance>();    
        try {
      	  String sql= "select wlan_test_result.strid,wlan_test_result.strtaskid,wlan_task_info.strtaskname,wlan_resc_hotpot.strcity,wlan_resc_hotpot.strtown," +
      	  		"rm_device.device_name,wlan_resc_hotpot.strhotpotname,strtext,wlan_test_result.dtcreatdate,wlan_resc_hotpot.strhotpotaddr," +
      	  		"intap_relevacy_sucrate, intap_relevacy_delay, intweb_auth_sucrate, intweb_off_sucrate, intpeap_auth_sucrate, intpeap_off_sucrate," +
      	  		"inthttp_req_sucrate, intping_sucrate, intftp_up_sucrate, intftp_down_sucrate, intuser_seg_sucrate, intuser_roam_sucrate, intweb_up_delay, " +
      	  		"intweb_down_delay, intpeap_up_delay, inthttp_resp_delay, intping_delay, intftp_up_speed, intftp_down_speed, intap_corr_suc_counts, " +
      	  		"intap_corr_total_counts, intweb_auth_suc_counts, intweb_auth_total_counts, intweb_off_suc_counts, intweb_off_total_counts, intpeap_auth_suc_counts, " +
      	  		"intpeap_auth_total_counts, intpeap_off_suc_counts, intpeap_off_total_counts, inthttp_req_suc_counts, inthttp_req_total_counts, intftp_up_suc_counts, " +
      	  		"intftp_up_total_counts, intftp_down_suc_counts, intftp_down_total_counts, intuser_seg_suc_counts, intuser_seg_total_counts, intuser_roam_suc_counts, " +
      	  		"intuser_roam_total_counts, intrssi from wlan_test_result,wlan_task_info,rm_device,wlan_resc_hotpot where wlan_test_result.strtaskid=wlan_task_info.strtaskid " +
      	  		"and wlan_test_result.strapmac=rm_device.strmac_addr and wlan_task_info.strhotpotname=wlan_resc_hotpot.strid and wlan_task_info.strtasktype='验收测试' " +
      	  		"and wlan_test_result.strnettype='WLAN'" + where;
          //System.out.println("检索所有信息的SQL："+sql);  
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                	Acceptance theBean = new Acceptance();
                    theBean = load(rs, false);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
        return beans;
    }
    
    //记录集的个数
    public int getCount(String where) {
        int count = 0;
        List<String> list = new ArrayList<String>();
        try {
        	String sql= "select * from wlan_test_result,wlan_task_info,rm_device,wlan_resc_hotpot " +
			"where wlan_test_result.strtaskid=wlan_task_info.strtaskid and wlan_test_result.strapmac=rm_device.strmac_addr " +
			"and wlan_task_info.strhotpotname=wlan_resc_hotpot.strid and wlan_task_info.strtasktype='验收测试' and " +
			"wlan_test_result.strnettype='WLAN'" + where;
            //System.out.println("列表记录集的SQL："+sql);
            ResultSet rs = db.executeQuery(sql);
            if(rs!=null){
    			while(rs.next()){
    				list.add(rs.getString("Strid"));
    			}
    		}
        } catch (Exception e) {
            e.printStackTrace();
        }
        count = list.size();
        db.closeCon();
        //System.out.println("输出记录集的个数："+count);
        return count;
    }
    
    //返回热点表中所有地市
    public List<String> returnCity() {
    	List<String> list = new ArrayList<String>();
          try {
              String strSql = "select distinct strcity from  wlan_resc_hotpot ";
              //System.out.println(strSql+"!!!!!!!!!!!!strtaskid");
              ResultSet rs = db.executeQuery(strSql);
              if (rs != null){
            	 while (rs.next()) {
                     list.add(rs.getString("STRcity"));
  				}
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          db.closeCon();
          return list;
      } 
    
    private String strcity;
    private String strid;
    public String getStrcity() {
		return strcity;
	}

	public void setStrcity(String strcity) {
		this.strcity = strcity;
	}

	public String getStrid() {
		return strid;
	}

	public void setStrid(String strid) {
		this.strid = strid;
	}

	private String strtown;
    public String getStrtown() {
		return strtown;
	}

	public void setStrtown(String strtown) {
		this.strtown = strtown;
	}

	private String strtaskname;

	public String getStrtaskname() {
		return strtaskname;
	}

	public void setStrtaskname(String strtaskname) {
		this.strtaskname = strtaskname;
	}

    private String strapname;
    private String strhpname;
    private String strtext;

	public String getStrapname() {
		return strapname;
	}

	public void setStrapname(String strapname) {
		this.strapname = strapname;
	}

	public String getStrhpname() {
		return strhpname;
	}

	public void setStrhpname(String strhpname) {
		this.strhpname = strhpname;
	}

	public String getStrtext() {
		return strtext;
	}

	public void setStrtext(String strtext) {
		this.strtext = strtext;
	}
	
	private String strtesttime;
	private String strhpaddr;

	public String getStrtesttime() {
		return strtesttime;
	}

	public void setStrtesttime(String strtesttime) {
		this.strtesttime = strtesttime;
	}

	public String getStrhpaddr() {
		return strhpaddr;
	}

	public void setStrhpaddr(String strhpaddr) {
		this.strhpaddr = strhpaddr;
	}
    
}
